﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NDF.Collections.Generic;
using NDF.DataAccess.Common;
using NDF.Reflection;
using System;
using System.Data;
using System.Linq;
using System.Reflection;

namespace NDF.Test.DataAccess
{
    [TestClass]
    public class MySqlDatabaseTest
    {
        [TestMethod]
        public void TestMethod1()
        {
            Database database = DatabaseFactories.CreateDatabase("MySqlContextTest");
            DataTable table = database.ExecuteDataTable("SELECT * FROM `user`");
            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine(row["Host"]);
            }
        }


        [TestMethod]
        public void TestMethod2()
        {
            DateTime startTime = DateTime.Now;

            Database database = DatabaseFactories.CreateDatabase("MySqlContextTest");
            DataTable table1 = database.ExecuteDataTable("SELECT * FROM `user` WHERE Host LIKE concat(@host, '%')", "local");
            foreach (DataRow row in table1.Rows)
            {
                Console.WriteLine(row["Host"]);
            }

            DateTime time1 = DateTime.Now;
            Console.WriteLine(time1 - startTime);

            DataTable table2 = database.ExecuteDataTable("SELECT * FROM `user` WHERE Host LIKE concat(@host, '%')", "host");
            foreach (DataRow row in table2.Rows)
            {
                Console.WriteLine(row["Host"]);
            }

            Console.WriteLine(DateTime.Now - time1);
        }

        [TestMethod]
        public void TestMethod3()
        {
            var array = AssemblyHelper.GetAssemblies().SelectMany(assembly => assembly.GetReferencedAssemblies()).Distinct().OrderBy(assembly => assembly.FullName);
            foreach (var item in array)
            {
                //Assembly.LoadFrom()
            }
        }
    }
}
